package http;
import java.io.ByteArrayOutputStream;  
import java.io.FileWriter;
import java.io.IOException;  
import java.io.InputStream;  
import java.net.URL;  
import java.net.URLConnection;  
  
public class DownLoadChm {  
  
    public static void main(String args[]) throws IOException {  
    	String path = "E:/sibuzhen/";
    	
    	for(int i=0;i<=130;i++){
    		URL url = new URL("http://zhsw.org/123/z/%D6%A4%B5%C0/sbzzdj/bookpath/"+i+".htm");  
            URLConnection conn = url.openConnection();  
            InputStream is = conn.getInputStream();  
            ByteArrayOutputStream out = new ByteArrayOutputStream();  
            byte[] b = new byte[1024];  
            int len = 0;  
            while ((len = is.read(b)) != -1) {  
                out.write(b, 0, len);  
            }  
            String result = out.toString("GB2312").replace("charset=gb2312", "charset=UTF-8");  
            out.close();  
            is.close();  
            
            FileWriter fileWriter = new FileWriter(path+i+".htm");
            fileWriter.write(result);
            fileWriter.flush();
            fileWriter.close();
    	}
        
        
    }  
  
}